<?php

session_start();

if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {

    header("Location: login.php");
}
//
include 'i_functions.php';
//
include 'i_LenderInit.php';
//
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $lender_ID = $_GET['lender_ID'];
    //print "lender_ID=" . $lender_ID . "<br>";
    $ID = htmlspecialchars($lender_ID);

    //==========================================
    //	CONNECT TO THE LOCAL DATABASE
    //==========================================
    $user_name = "root";
    $pass_word = "haddons";
    $database = "PPI";
    $server = "127.0.0.1";

    $db_handle = mysql_connect($server, $user_name, $pass_word);
    $db_found = mysql_select_db($database, $db_handle);

    if ($db_found && $lender_ID != "NEW") {

        $SQL = "SELECT * FROM lenders WHERE ID = '$ID'";
        //print $SQL . "<br>";
        $result = mysql_query($SQL);
        $num_rows = mysql_num_rows($result);
        //====================================================
        //	CHECK TO SEE IF THE $result VARIABLE IS TRUE
        //====================================================
        if ($result) {
            include 'i_head.php';
            if ($num_rows > 0) {
                $db_field = mysql_fetch_assoc($result);
                /* foreach ($db_field as $key_name => $key_value) {
                  print $key_name . "=" . $key_value . "<BR>";
                  } */
                //$ID = $db_field['ID'];
                $lendername = $db_field['LenderName'];
                $address1 = $db_field['Address1'];
                $address2 = $db_field['Address2'];
                $address3 = $db_field['Address3'];
                $city = $db_field['City'];
                $postcode = $db_field['Postcode'];
                $telno = $db_field['TelNo'];
                $faxno = $db_field['FaxNo'];
                $email = $db_field['Email'];
                $fscs = $db_field['FSCS'];
                if ($fscs == "Y") {
                    $fscs_y = "checked";
                } else {
                    $fscs_n = "checked";
                }
                $fosq = $db_field['FOSQ'];
                if ($fosq == "Y") {
                    $fosq_y = "checked";
                } else {
                    $fosq_n = "checked";
                }

                include 'i_LenderForm.php';
            } else {
                $message = "not found!";
                print $message;
            }
            include 'i_foot.html';
        }
    } else {
        print "should be here<br>";
        include 'i_head.php';
        include 'i_LenderForm.php';
        include 'i_foot.html';
    }
}
?>